package com.starmark.gateway.log.access.listener;


import com.alibaba.fastjson.JSON;
import com.starmark.gateway.log.access.disruptor.publisher.LogEventPublisher;
import com.starmark.gateway.log.access.entity.GatewayAccessLog;
import com.starmark.message.queue.consumer.api.service.IMessageQueueConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 访问日志处理
 */
@Service
public class GatewayAccessLogListener implements  IMessageQueueConsumerService {
    @Value("${starmark.log.access.kafka.topic:accessLog}")
    private String accessLogTopic;
    @Autowired
    private LogEventPublisher logEventPublisher;

    @Override
    public void receiveMessage(String message) {
        GatewayAccessLog accessLog = JSON.parseObject(message, GatewayAccessLog.class);
        logEventPublisher.publishEvent(accessLog);
    }



    @Override
    public String topic() {
        return accessLogTopic;
    }

    @Override
    public boolean support(String consumerType) {
        return  Objects.equals(consumerType,"redis");
    }


}


